package com.asg.guesswhat;

import java.util.StringTokenizer;

/**
 * This class is an extendible super class for the card set types
 * 
 * @author blakbro2k
 */
public class CardSet {
	/** Number of cards used in set */
	private int cardsUsed;
	/** max card set size */
	private static final int MAX_CARD_LIMIT = 24;
	/** cards in set */
	protected Card[] cards;
	/** Name of card set */
	public String name;
	/** Cardset config */
	public Config cardSetcfg;

	/**
	 * Must define a generic constructor for other classes to implement
	 */
	public CardSet() {
		
	}	
	
	/**
	 * Must define a generic constructor for other classes to implement
	 */
	public CardSet(String[] cardSetFile) {
		buildCardSet(cardSetFile);
	}
	
	public void buildCardSet(String[] cardSetObj){
		//cardSetcfg = new Config(cardSetFile);
		//name = cardSetcfg.getProperty("cardsetname");
		name = cardSetObj[0];
		cards = new Card[MAX_CARD_LIMIT+1];
		for(int i = 1; i < MAX_CARD_LIMIT;i ++){
			StringTokenizer st = new StringTokenizer(cardSetObj[i], ";");
			//cards[i] = new Card(cardSetcfg.getProperty("name" + (i+1)),null,null,null);
			//new Card(parseCardName(cardSetObj[i],new Texture(parseCardTextureRegion(cardSetObj[i])),,);
			//parseCardTextureRegion(cardSetObj[i]);
			//parseCardFeature(cardSetObj[i]);
			cards[i] = new Card(st.nextToken(),null,null,null);
		}
		cardsUsed = 0;
	}

/**
 * gets the Next Card in Set, throws IllegalStateException if empty
 * 
 * @return Card
 */
	public Card getNextCard() {
		if(isEmpty()){
			throw new IllegalStateException("No cards are left in the set.");
		}
		cardsUsed++;
		return cards[cardsUsed-1];
	}
	
	/**
	 * Put all the used cards back into deck
	 * shuffle the deck into a random order
	 *
	   public void shuffle() {
		      for ( int i = cards.length-1; i > 0; i-- ) {
		         int rand = (int)(Math.random()*(i+1));
		         Card temp = cards[i];
		         cards[i] = cards[rand];
		         cards[rand] = temp;
		      }
		      cardsUsed = 0;
		   }*/
	
	/**
	 * Returns the number of cards left in set
	 * 
	 * @return int
	 */
	   public int cardsLeft() {
		      return cards.length - cardsUsed;
		   }
	
	/**
	 * Checks if Card Set is empty
	 * 
	 * @return
	 */
	public boolean isEmpty(){
		return MAX_CARD_LIMIT == cardsUsed;
	}
	
	/**
	 * Gets the Card Set limit
	 * 
	 * @return int
	 */
	public int getMaxCardLimit() {
		return MAX_CARD_LIMIT;
	}

	/**
	 * Gets the Card Set Name
	 * 
	 * @return name Name of Card 
	 */
	public String getCardSetName() {
		return name;
	}
}